﻿using AvalonDock.Layout;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using OpenTK.Windowing.GraphicsLibraryFramework;
using ServoDrivesLib.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 雷赛板卡上位机.Models;
using 雷赛板卡上位机.ViewModel;

namespace 雷赛板卡上位机.Services
{
    public static class ControlService
    {
        private static ControlType _control;
        public static ControlType GetControlType()
        {
            if (_control == 0)
            {
                _control = WeakReferenceMessenger.Default.Send<RequestMessage<ControlType>,string>("ControlCard");
            }
            return _control;
        }

        public static LayoutDocument GetViewModel<T>(string title, int id = 0) where T : class
        {
            LayoutDocument layout = App.GetService<LayoutDocument>();
            T ret = App.GetService<T>();
            layout.Title = title;
            layout.Content = ret;
            switch (ret)
            {
                case AxisControlViewModel axisControlViewModel:
                    axisControlViewModel.AxisIndex = id;
                    break;
            }

            return layout;
        }
        public static InputTextBoxViewModel GetInputTextBoxViewModel()
        {
            return App.GetService<InputTextBoxViewModel>();
        }

        public static AxisControlViewModel GetAxisControlViewModel()
        {
            return App.GetService<AxisControlViewModel>();
        }
    }
}
